import sys
import time
import base64
import sha

def encode_conf(self, strs, key, isEncrypt=1):
    if(strs == '' or key == ''):
        return;
    now_time = time.time()
    dynKey = sha.new(str(now_time)).hexdigest() if isEncrypt == 1 else strs[0:40]
    fixedkey = sha.new(key).hexdigest()
    dynkeypart1 = dynKey[0:20]
    dynkeypart2 = dynKey[20:]
    fixedketpt1 = fixedkey[0:20]   
    fixedketpt2 = fixedkey[20:]
    newkey = sha.new(dynkeypart1 + fixedketpt1 + dynkeypart2 + fixedketpt2).hexdigest()

    if (isEncrypt == 1):
        newstring = fixedketpt1 + strs + dynkeypart2
    else:
        newstring = base64.b64decode(strs[40:].replace('_', '='))

    result = ''
    strlen = len(newstring)
    for i in range(0, strlen):
        j = i % 40
        result += chr(ord(newstring[i]) ^ ord(newkey[j]))

    return dynKey + base64.b64encode(result).replace('=', '_') if isEncrypt == 1 else result[20:-20]